package com.monise.view;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import java.awt.Choice;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;

import com.monise.model.Informacao;

import java.awt.Component;

public class TelaInformacao extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTextField txtCardapio;
	private JTextField txtArquivoSaldo;
	private JTextField txtNomeVendedor;
	private JTextField txtNomeEvento;
	private JTextField txtCodSeguranca;
	private JButton btnAbrirCardapio;
	String nomeArquivo = "", caminhoArquivo = "";
	private JFileChooser arquivo = new JFileChooser();
	private Informacao informacao;

	/**
	 * Create the panel.
	 */
	public TelaInformacao(final FramePrincipal frame) {
		
		JLabel lblCarregarArquivoDe = new JLabel("Carregar arquivo de card\u00E1pio:");
		informacao = new Informacao();
		
	    btnAbrirCardapio = new JButton("Abrir arquivo");
		btnAbrirCardapio.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				arquivo.showOpenDialog(btnAbrirCardapio);
				nomeArquivo = arquivo.getSelectedFile().getName();
				
				caminhoArquivo = arquivo.getSelectedFile().getAbsolutePath();
				txtCardapio.setText(caminhoArquivo);
				informacao.setCardapio(caminhoArquivo);
			//	arq = arquivo.getSelectedFile().getAbsolutePath();
				frame.setInformacao(informacao);
				
			}
		});
		
		JLabel lblDiretrioParaSalvar = new JLabel("Diret\u00F3rio para salvar informa\u00E7\u00F5es:");
		
		final JButton btnSalvarArquivo = new JButton("Salvar arquivo");
		btnSalvarArquivo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				arquivo.showOpenDialog(btnSalvarArquivo);
				nomeArquivo = arquivo.getSelectedFile().getName();
				
				caminhoArquivo = arquivo.getSelectedFile().getAbsolutePath();
				txtArquivoSaldo.setText(caminhoArquivo);
				informacao.setArquivoSaldo(caminhoArquivo);
				frame.setInformacao(informacao);
			//	arq = arquivo.getSelectedFile().getAbsolutePath();
				
			}
		});
		
		txtCardapio = new JTextField();
		txtCardapio.setColumns(10);
		
		txtArquivoSaldo = new JTextField();
		txtArquivoSaldo.setColumns(10);
		
		JLabel lblInformeONome = new JLabel("Informe o nome do vendedor:");
		
		JLabel lblInformeONome_1 = new JLabel("Informe o nome do evento:");
		
		JLabel lblInformeOCdigo = new JLabel("Informe o c\u00F3digo de seguran\u00E7a:");
		
		txtNomeVendedor = new JTextField();
		txtNomeVendedor.setColumns(10);
		
		txtNomeEvento = new JTextField();
		txtNomeEvento.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				informacao.setEvento(txtNomeEvento.getText());
			}
		});
		txtNomeEvento.setColumns(10);
		
		txtCodSeguranca = new JTextField();
		txtCodSeguranca.setColumns(10);
		
		informacao.setCodigoSeguranca(txtCodSeguranca.getText());
		informacao.setEvento(txtNomeEvento.getText());
		informacao.setVendedor(txtNomeVendedor.getText());
		
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(29)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblCarregarArquivoDe)
						.addComponent(lblDiretrioParaSalvar)
						.addComponent(lblInformeONome)
						.addComponent(lblInformeONome_1)
						.addComponent(lblInformeOCdigo))
					.addGap(10)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
						.addComponent(txtCardapio, GroupLayout.PREFERRED_SIZE, 298, GroupLayout.PREFERRED_SIZE)
						.addComponent(txtArquivoSaldo, 287, 287, 287)
						.addComponent(txtNomeVendedor, GroupLayout.PREFERRED_SIZE, 328, GroupLayout.PREFERRED_SIZE)
						.addComponent(txtNomeEvento, 328, 328, 328)
						.addComponent(txtCodSeguranca, 327, 327, 327))
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(btnSalvarArquivo)
						.addComponent(btnAbrirCardapio))
					.addContainerGap(69, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(62)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblCarregarArquivoDe, Alignment.TRAILING)
						.addComponent(txtCardapio, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnAbrirCardapio, Alignment.TRAILING))
					.addGap(31)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblDiretrioParaSalvar, Alignment.TRAILING)
						.addComponent(txtArquivoSaldo, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnSalvarArquivo, Alignment.TRAILING))
					.addGap(36)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblInformeONome, Alignment.TRAILING)
						.addComponent(txtNomeVendedor, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(39)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblInformeONome_1, Alignment.TRAILING)
						.addComponent(txtNomeEvento, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(26)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblInformeOCdigo, Alignment.TRAILING)
						.addComponent(txtCodSeguranca, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(66, Short.MAX_VALUE))
		);
		groupLayout.linkSize(SwingConstants.HORIZONTAL, new Component[] {txtCardapio, txtArquivoSaldo, txtNomeVendedor, txtNomeEvento, txtCodSeguranca});
		setLayout(groupLayout);

	}
}
